#include <QDebug>

#include "linkmanager.h"
#include "blogmanager.h"
#include "topicmanager.h"

LinkManager::LinkManager(QObject *parent) :
    QObject(parent)
{
}

void LinkManager::handleLink(const QString &link, CVTabWidget *widget)
{
    if (!link.isEmpty() && widget != NULL)
    {
        QStringList list = link.split("/");
        if (list.size() >= 2)
        {
            QString type = list.at(0);
            if (type == "object" && list.size() == 3)
            {
                QString subtype = list.at(1);
                QString id = list.at(2);
                if (subtype == "blog")
                {
                    BlogManager *blogMgr = new BlogManager();
                    blogMgr->getBlog(id);
                    connect(blogMgr, SIGNAL(handleBlog(Blog*,QString)), widget, SLOT(addBlogTab(Blog*,QString)));
                }
                else if (subtype == "forumtopic")
                {
                    TopicManager *topicMgr = new TopicManager();
                    topicMgr->getTopic(id);
                    connect(topicMgr, SIGNAL(handleTopic(Topic*,QString)), widget, SLOT(addTopicTab(Topic*,QString)));
                }
            }
            else if (type == "user" || type == "site")
            {

            }
        }
    }
    else
    {
        qDebug() << "Link is empty ? " << link;
        qDebug() << "Or widget is empty";
    }
}
